package unit04.day01;

import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * 若想提高读写效率，可以通过提高每次读写的数据量来减少读写次数
 * @author cola
 *
 */
public class CopyDemo2 {
	
	public static void main(String[] args) throws IOException {
		RandomAccessFile src = new RandomAccessFile("1.ts","r");
		RandomAccessFile dest = new RandomAccessFile("2.ts","rw");
		/*
		 * int read(byte[] data)
		 * 一次性尝试读取给定字节数总长度的字节量并存入到该数组中，返回值为实际读取到的字节量，若返回值为-1
		 * 则表示本次没有读取到任何数据
		 * */
		//10k
		byte[] data = new byte[1024*10];
		int len = -1;
		long start = System.currentTimeMillis();
		while((len = src.read(data)) != -1) {
			dest.write(data,0,len);
		}
		long end = System.currentTimeMillis();
		System.out.println("耗时："+(end - start));
		src.close();
		dest.close();
	}
}
